.cu.o:
	$(nvcc) $(NVCXXFLAGS) -c -o $@ $<

# get the current version from Mercurial
HGVERSION:= $(shell hg -R $(top_srcdir) id --id --branch --tags 2> /dev/null || grep node $(top_srcdir)/.hg_archival.txt 2> /dev/null || true )
AM_CPPFLAGS = -DMCRXVERSION="\"${HGVERSION}\""

mcrxversion.cc: hgstamp
hgstamp: dummy
	[ -f $@ ] || touch $@
	echo $(HGVERSION) | cmp -s $@ - || echo $(HGVERSION) > $@
dummy: ;

AM_CXXFLAGS = ${PTHREAD_CFLAGS}
# because libPJutil is included in LDFLAGS, and it needs boost, we add
# it unconditionally but on some systems, AM_LDFLAGS is not included
# in the link without adding it to the target's xxx_LDFLAGS
AM_LDFLAGS = $(BOOST_LDFLAGS) $(BOOST_THREAD_LIB)

bin_PROGRAMS = sfrhist  cmprauxfits mcrx broadband  
noinst_LIBRARIES = libmcrx.a

if WITH_CUDA
MCRXCUDA_SOURCES = cuda_grain_temp.cu
MCRXCUDA_LIBS = $(CUTIL_LIB) -lcudart
endif

if WITH_X11
X11_LIBS = -lGL -lGLU -lX11
endif

if WITH_AREPO
AREPO_SOURCES = mcrx-arepo.cc
AREPO_LIBS = -larepo -lgsl -lgmp $(MPI_LIBS)
endif

# libmcrx
libmcrx_a_SOURCES = aux_emergence.cc aux_grid.cc bhmodel.cc	      \
	blackbody.cc cooling.cc create_grid.cc density_generator.cc   \
	emergence.cc full_sed_emergence.cc full_sed_grid.cc	      \
	gadgetquant.cc grain.cc grain_size.cc imops.cc ir_grid.cc     \
	mcrx-units.cc model.cc mono_poly_abstract.cc multiphase.cc    \
	particle_set.cc polychromatic_grid.cc projection.cc random.cc \
	ray.cc single_lambda_emergence.cc snapshot-art.cc	      \
	snapshot-enzo.cc snapshot-hdf5.cc snapshot-tipsy.cc	      \
	snapshot.cc sphparticle.cc thermal_equilibrium_grain.cc	      \
	threadlocal.cc vecops.cc xvisualinfo_class.c mcrxversion.cc	   \
	$(MCRXCUDA_SOURCES) $(AREPO_SOURCES)	
libmcrx_a_CXXFLAGS= $(AM_CXXFLAGS) $(MPI_CXXFLAGS)


# sfrhist
sfrhist_SOURCES = makegrid.cc sfrhist-calculation.cc sfrhist.cc \
sfrhist_snapshot.cc sphgrid-fits.cc sphgrid.cc
sfrhist_LDADD = -lmcrx $(AREPO_LIBS)
sfrhist_LDFLAGS = -L. $(AM_LDFLAGS)
sfrhist_DEPENDENCIES = libmcrx.a

# cmprauxfits
cmprauxfits_SOURCES = cmprauxfits.cc

# mcrx
mcrx_SOURCES = monitor.cc aux_grid_stage.cc aux_particle_stage.cc \
	grain_model_factory.cc intensity_stage.cc		  \
	ir_intensity_stage.cc ir_stage.cc mcrx-extras.cc	  \
	mcrx-extras2.cc mcrx-stage.cc mcrx.cc nonscatter_stage.cc \
	scatter_stage.cc thick_ir_stage.cc
mcrx_LDADD = -lmcrx $(MCRXCUDA_LIBS) $(X11_LIBS) $(AREPO_LIBS)
mcrx_LDFLAGS = -L. $(MPI_LDFLAGS) $(AM_LDFLAGS)
mcrx_DEPENDENCIES = libmcrx.a

# broadband
broadband_SOURCES = broadband.cc 
broadband_LDADD = -lmcrx
broadband_LDFLAGS = -L. $(AM_LDFLAGS)
broadband_DEPENDENCIES = libmcrx.a
